import React from "react";
import axios from 'axios'
axios.defaults.timeout=6000


class QuerIP extends React.Component {
  constructor() {
    super();
    this.state = {
      ipaddres: "",
     
    };
  }

     Getip=()=> {
        let val = this.refs.ip.value;
        this.state = ({
          ipaddres: val,
        });
       console.log(this.state.ipaddres)
     
}
changlzque = () => {
  const w = window.open("http://43.153.69.17:8081");
};
changlzque1 = () => {
  const w = window.open("http://43.153.69.17:8002");
};
refr = () => {
 window.location.reload() ;
};


// 测试下
// ceshi=()=>{
//   axios.get("http://ipconfig.io").then(
//     res=>{
//       console.log(res)
//     }
//   ).catch(
//     err=>{
//       console.log(err)
//     }
//   )
// }
tj=()=>{
    const http="http://";
    const port=":31401";
    const text= this.state.ipaddres;
    axios.get(http+text+port).then(
        res=>{
            const number = res.data.core_latest_ledger
            this.setState({
                ipaddres:number
            })
            console.log(res.data.core_latest_ledger)
            
        }
    ).catch(
        err=>{
            this.setState({
                ipaddres:"获取区块错误"
            })
        }

    )


}


  render() {
    return (
      <div>
        <center>
       请输入ip地址：<input placeholder="请输入正确的ip地址" ref="ip" onChange={this.Getip}></input> <br></br>
       节点区块高度：<input placeholder="1是新作的" type='text' value={this.state.ipaddres}></input><br></br>
       <button onClick={this.tj}>查询</button> <button onClick={this.changlzque}>日志上传</button>  <button onClick={this.changlzque1}>查看日志</button> 
<button onClick={this.refr}>刷新</button> 
       {/* <button onClick={this.ceshi}>ceshi</button>  */}
       </center>

      </div>
    );
  }
}

export default QuerIP;
